<%--
  Created by IntelliJ IDEA.
  User: 27716
  Date: 2024/10/29
  Time: 12:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改</title>
    <script src="../../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../static/css/css.css">
    <script>
        $(function (){
            $.ajaxSettings.async =false;
            getGoodsType();
            getSupplierSelect();
            //回显
            findById();
        })
        //下拉框
        function  getGoodsType(){
            $.ajax({
                url:"/goodsType/goodsType",
                dataType: "json",
                success(res) {
                    for (let o of res) {
                        $("#goodsTypeId").append(`
                            <option value="\${o.goodsTypeId}">\${o.goodsTypeName}</option>
                    `)
                    }

                },
                error() {
                    alert("服务器错误")
                }
            })
        }
        //下拉框
        function getSupplierSelect(){
            $.ajax({
                url:"/supplier/getSupplier",
                dataType:"json",
                success(res){
                    for (let o of res) {
                        $("#supplierId").append(`
                            <option value="\${o.supplierId}">\${o.supplierName}</option>
                        `)
                    }
                },
                error(){
                    alert("服务器出现问题")
                }
            })
        }
        //回显
        function findById(){
            let goodsId = $("#goodsId").val();
            let obj = {goodsId:goodsId};
            $.ajax({
                url:"/goodschange/findById",
                type:"post",
                data:{reqInfos:JSON.stringify(obj)},
                dataType:"json",
                success(res){
                    $("#goodsCode").val(res.goodsCode);
                    $("#goodsName").val(res.goodsName);
                    $("#inventoryQuantity").val(res.inventoryQuantity);
                    $("#goodsTypeId").val(res.goodsTypeId);
                    $("#supplierId").val(res.supplierId);
                },
                error(){
                    alert("服务器出现问题")
                }
            })
        }

    </script>
</head>
<body>
<input type="hidden" id="goodsId" value="${param.goodsId}">
商品编码：<input type="text" id="goodsCode"> <br>
商品名称：<input type="text" id="goodsName"> <br>
库存数量：<input type="text" id="inventoryQuantity"> <br>
商品名：<select id="goodsTypeId">
    <option value="">请选择</option>
</select> <br>
供应商名称： <select  id="supplierId">
    <option value="">请选择</option>
</select>
    <input type="button" value="修改" id="getUpd">
</body>
<script>
    $("#getUpd").click(function (){
        let goodsCode = $("#goodsCode").val();
        let goodsName = $("#goodsName").val();
        let inventoryQuantity = $("#inventoryQuantity").val();
        let goodsTypeId = $("#goodsTypeId").val();
        let supplierId = $("#supplierId").val();
        let obj = {goodsCode,goodsName,inventoryQuantity,goodsTypeId,supplierId};
        $.ajax({
            url:"/goodschange/getUpd",
            type: "post",
            data: {reqInfos:JSON.stringify(obj)},
            dataType:"json",
            success(res){
                console.log(res);
                if(res === 200){
                    alert("修改成功");
                    location.href = "list.jsp";
                }
            },
            error(){
                alert("服务器错误")
            }
        })
    })
</script>
</html>
